Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

preact

Package Overview
Dependencies
Maintainers
9
Versions
248
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preact

Fast 3kb React-compatible Virtual DOM library.

  • 10.25.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.3M
decreased by-5.84%
Maintainers
9
Weekly downloads
 
Created

What is preact?

Preact is a fast, 3kB alternative to React with the same modern API. It provides the thinnest possible Virtual DOM abstraction on top of the DOM. Its goal is to provide the same rich and robust ecosystem that React has, while being leaner and more efficient, often used for performance-critical applications and situations where bundle size is a factor.

What are preact's main functionalities?

Creating Components

This code sample demonstrates how to create a simple Preact component and render it to the DOM. It's similar to React but with a smaller footprint.

import { h, render, Component } from 'preact';

class MyComponent extends Component {
  render() {
    return <div>Hello, Preact!</div>;
  }
}

render(<MyComponent />, document.body);

Using Hooks

This code sample shows how to use hooks in Preact, specifically the useState hook to create a simple counter component.

import { h, render, useState } from 'preact/hooks';

function Counter() {
  const [count, setCount] = useState(0);
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

render(<Counter />, document.body);

Preact/Compat

This code sample illustrates how to use Preact/Compat to achieve React compatibility, allowing developers to use Preact as a drop-in replacement for React.

import React from 'preact/compat';
import ReactDOM from 'preact/compat';

function App() {
  return <h1>Hello from Preact/Compat</h1>;
}

ReactDOM.render(<App />, document.getElementById('app'));

Other packages similar to preact

Keywords

FAQs

Package last updated on 02 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc